#include <QCoreApplication>
#include <QDebug>

#include <iostream>

using namespace std;

void test0()
{
    QString s1("hello");
    QString s2 = s1;

    qDebug() << "s1 = " << s1
             << "s2 = " << s2;
    //QString的底层采用的是隐式共享（也就是写时复制）
    qDebug() << "s1.constData() = " << s1.constData();
    qDebug() << "s2.constData() = " << s2.constData();

    qDebug() << endl << endl;
    s2[0] = 'H';
    qDebug() << "s1 = " << s1
             << "s2 = " << s2;
    //QString的底层采用的是隐式共享（也就是写时复制）
    qDebug() << "s1.constData() = " << s1.constData();
    qDebug() << "s2.constData() = " << s2.constData();

    //在Qt中，推荐使用qDebug进行打印
    //printf("s1.constData() = %p\n", s1.constData());
    //qDebug("qdebug s1.constData() = %p\n", s1.constData());
    //cout << "s1.constData() = " << s1.constData();

    //在Qt中，打印QString的时候，可以使用格式化输出arg  %1  %2
    //表示第几个值
    qDebug() << QString("我爱你王道 %1 %2").arg(3).arg("年");
}

void test()
{
    QString s1("hello");

    QByteArray ba = s1.toUtf8();
    qDebug() << "ba = " << ba ;

    QString s2;
    s2 = QString::fromUtf8(ba);
    qDebug() << "s2 = " << s2;

    qDebug() << __FUNCTION__
             << __FILE__
             << __LINE__;
}

void test2()
{
    QString s1("hello");
    //去掉双引号的方式
    qDebug().noquote() << "s1 =" << s1;
    qDebug() << "s1 =" << s1.toUtf8().data();
    //去掉空格
    qDebug().nospace() << "s1 =" << s1.toUtf8().data();
    qDebug() << "s1 =" << s1.trimmed();
    qDebug() << "s1 =" << s1;
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    test2();
    return a.exec();
}
